package com.ch04.service;


import com.ch04.mapper.DormitoryMapper;
import com.ch04.pojo.Dormitory;
import com.ch04.utils.MyBatisSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

/**
 * @ClassName DormitoryService
 * @Description TODO
 * @Author Kx
 * @Date 2025/4/23 15:37
 * @Version 1.0
 */
public class DormitoryService {
    /**
     * @param dormitoryId : 宿舍编号
     * @return com.ch04.pojo.Dormitory
     * @author: kx
     * @date: 2025/4/23 19:45
     * @description: 根据id查询宿舍信息
     */
    public Dormitory getDormitoryById(int dormitoryId) {
        // 获取sqlSession
        try (SqlSession sqlSession = MyBatisSqlSessionFactory.getSqlSession()) {
            return sqlSession.getMapper(DormitoryMapper.class).getDormitoryId(dormitoryId);
        }
    }

    /**
     * @param name    : 姓名
     * @param clsName : 班级
     * @return com.ch04.pojo.Dormitory
     * @author: kx
     * @date: 2025/4/23 19:49
     * @description: 根据姓名和班级查询宿舍信息
     */
    public Dormitory getDormitory(String name, String clsName) {
        // 获取sqlSession
        try (SqlSession sqlSession = MyBatisSqlSessionFactory.getSqlSession()) {
            return sqlSession.getMapper(DormitoryMapper.class).getDormitory(name, clsName);
        }
    }

}
